package C049;

/**
 * ClassName: C01
 * Package: C049
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/16 22:23
 * @Version 1.0
 * @Since 1.0
 */
public class C01 {
    public static void main(String[] args) {
//        int[] arr = {2,3,1,2,4,3};
        int[] arr = {1, 4, 4};
        System.out.println(minSubArrayLen(4, arr));
    }


    public static int minSubArrayLen(int target, int[] nums) {
        int sum = 0;
        int res = Integer.MAX_VALUE;
        for (int l = 0, r = 0; r < nums.length; r++) {
            sum += nums[r];
            while (sum - nums[l] >= target) {
                sum -= nums[l];
                l++;
            }
            if (sum >= target) {
                res = Math.min(res, r - l + 1);
            }
        }
        return res == Integer.MAX_VALUE ? 0 : res;
    }
}
